﻿/******************************************************************************
 * 
 * 域名     : GreatB2C.Common
 * 类名		: DataDefine.cs
 * 功能描述	: 数据定义，当作数据协议，统一各模块间的命名

 * 处理流程	:
 * 算法描述	:
 * 作 者	: 王超
 * 日 期	: 
 * 修 改	:
 * 日 期	:
 * 版 本	:
 * 使用方法 : 可以在读取和赋值时,统一各模块间的命名,不致于各个模块间的命名不一致

 *            ,用法如下:
 *              using Utility.DataDefine;
 *
 *              Session[enuSession.UserID] = "";
 * ***************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace GreatB2C.Utility
{
    /// <summary>
    /// 数据定义，当作数据协议，统一各模块间的命名
    /// </summary>
    [Serializable]
    public class DataDefine
    {
        #region 通用数据定义

        /// <summary>
        /// 操作类型
        /// </summary>
        public enum OperateType
        {
            /// <summary>
            /// 模块浏览
            /// </summary>
            View = 1 ,               // 1.模块浏览
            /// <summary>
            /// 查询
            /// </summary>
            Query ,                  // 2.查询
            /// <summary>
            /// 添加
            /// </summary>
            Insert ,                 // 3.添加
            /// <summary>
            /// 更新
            /// </summary>
            Update ,                 // 4.更新
            /// <summary>
            /// 删除
            /// </summary>
            Delete ,                 // 5.删除
            /// <summary>
            /// 导入
            /// </summary>
            Import ,                 // 6.导入
            /// <summary>
            /// 导出
            /// </summary>
            Export ,                 // 7.导出
            /// <summary>
            /// 审批
            /// </summary>
            Audit ,                   // 8.审批
            /// <summary>
            /// 打印
            /// </summary>
            Print                    // 9.打印
        }

        /// <summary>
        /// 获取操作类型说明
        /// </summary>
        /// <param name="itype">枚举类型-操作类型</param>
        /// <returns></returns>
        public static string GetOperateType( int itype )
        {
            object value = itype;
            if ( Enum.IsDefined( typeof( OperateType ) , value ) )
            {
                OperateType etype = ( OperateType ) itype;
                switch ( etype )
                {
                    case OperateType.View:
                        return "模块浏览";
                    case OperateType.Query:
                        return "查询";
                    case OperateType.Insert:
                        return "添加";
                    case OperateType.Update:
                        return "更新";
                    case OperateType.Delete:
                        return "删除";
                    case OperateType.Import:
                        return "导入";
                    case OperateType.Export:
                        return "导出";
                    case OperateType.Audit:
                        return "审批";
                    case OperateType.Print:
                        return "打印";
                }
            }

            return "";
        }

        /// <summary>
        /// 性别 
        /// </summary>
        public enum Gender
        {
            /// <summary>
            /// 女
            /// </summary>
            Female = 1,			            // 女
            /// <summary>
            /// 男
            /// </summary>
            Male					        // 男
        }

        /// <summary>
        /// 获取性别说明
        /// </summary>
        /// <param name="itype">枚举类型-性别</param>
        /// <returns></returns>
        public static string GetGender( int itype )
        {
            object value = itype;
            if ( Enum.IsDefined( typeof( Gender ) , value ) )
            {
                Gender etype = ( Gender ) itype;
                switch ( etype )
                {
                    case Gender.Female:
                        return "女";
                    case Gender.Male:
                        return "男";
                }
            }

            return "";
        }

        /// <summary>
        /// 是否状态 ( No/Yes )
        /// </summary>
        public enum Status_YN
        {
            /// <summary>
            /// 否
            /// </summary>
            No = 1 ,                    // 否
            /// <summary>
            /// 是
            /// </summary>
            Yes						    // 是
        }

        /// <summary>
        /// 获取是否状态说明
        /// </summary>
        /// <param name="itype">枚举类型-是否状态</param>
        /// <returns></returns>
        public static string GetStatus_YN( int itype )
        {
            object value = itype;
            if ( Enum.IsDefined( typeof( Status_YN ) , value ) )
            {
                Status_YN etype = ( Status_YN ) itype;
                switch ( etype )
                {
                    case Status_YN.No:
                        return "否";
                    case Status_YN.Yes:
                        return "是";
                }
            }

            return "";
        }

        /// <summary>
        /// 操作结果
        /// </summary>
        public enum OperateResult
        {
            /// <summary>
            /// 失败
            /// </summary>
            Failed = 1 ,                // 失败
            /// <summary>
            /// 成功
            /// </summary>
            Success                     // 成功
        }

        /// <summary>
        /// 获取操作结果说明
        /// </summary>
        /// <param name="itype">枚举类型-操作结果</param>
        /// <returns></returns>
        public static string GetOperateResult( int itype )
        {
            object value = itype;
            if ( Enum.IsDefined( typeof( OperateResult ) , value ) )
            {
                OperateResult etype = ( OperateResult ) itype;
                switch ( etype )
                {
                    case OperateResult.Failed:
                        return "失败";
                    case OperateResult.Success:
                        return "成功";
                }
            }

            return "";
        }

        /// <summary>
        /// 异常类型定义
        /// </summary>
        public enum ExceptionType
        {
            /// <summary>
            /// 消息提示
            /// </summary>
            Information = 1 ,           // 消息提示
            /// <summary>
            /// 警告
            /// </summary>
            Warning ,                   // 警告
            /// <summary>
            /// 错误
            /// </summary>
            Error ,                     // 错误
            /// <summary>
            /// 严重错误
            /// </summary>
            FatalError                  // 严重错误
        }

        /// <summary>
        /// 获取异常类型定义说明
        /// </summary>
        /// <param name="itype">枚举类型-异常类型定义</param>
        /// <returns></returns>
        public static string GetExceptionType( int itype )
        {
            object value = itype;
            if ( Enum.IsDefined( typeof( ExceptionType ) , value ) )
            {
                ExceptionType etype = ( ExceptionType ) itype;
                switch ( etype )
                {
                    case ExceptionType.Information:
                        return "消息提示";
                    case ExceptionType.Warning:
                        return "警告";
                    case ExceptionType.Error:
                        return "错误";
                    case ExceptionType.FatalError:
                        return "严重错误";
                }
            }

            return "";
        }

        /// <summary>
        /// 帐号状态
        /// </summary>
        public enum UserStatus
        {
            /// <summary>
            /// 正常
            /// </summary>
            Normal = 1 ,    // 正常     1
            /// <summary>
            /// 已冻结
            /// </summary>
            Locked ,        // 冻结     2
            /// <summary>
            /// 帐号无效
            /// </summary>
            UnValid         // 帐号无效   3
        }

        /// <summary>
        /// 获取帐号状态说明
        /// </summary>
        /// <param name="itype">枚举类型-帐号状态</param>
        /// <returns></returns>
        public static string GetUserStatus( int itype )
        {
            object value = itype;
            if ( Enum.IsDefined( typeof( UserStatus ) , value ) )
            {
                UserStatus etype = ( UserStatus ) itype;
                switch ( etype )
                {
                    case UserStatus.Normal:
                        return "正常";
                    case UserStatus.Locked:
                        return "冻结";
                    case UserStatus.UnValid:
                        return "帐号无效";
                }
            }

            return "";
        }

        /// <summary>
        /// 证件类型
        /// </summary>
        public enum CertType
        {
            /// <summary>
            /// 身份证
            /// </summary>
            PersonalID = 1 ,
            /// <summary>
            /// 学生证
            /// </summary>
            StudentID ,
            /// <summary>
            /// 护照
            /// </summary>
            PassportID ,
            /// <summary>
            /// 其它
            /// </summary>
            Other
        }

        /// <summary>
        /// 获取证件类型说明
        /// </summary>
        /// <param name="itype">枚举类型-证件类型</param>
        /// <returns></returns>
        public static string GetCertType( int itype )
        {
            object value = itype;
            if ( Enum.IsDefined( typeof( CertType ) , value ) )
            {
                CertType etype = ( CertType ) itype;
                switch ( etype )
                {
                    case CertType.PersonalID:
                        return "身份证";
                    case CertType.StudentID:
                        return "学生证";
                    case CertType.PassportID:
                        return "护照";
                    case CertType.Other:
                        return "其它";
                }
            }

            return "";
        }

        /// <summary>
        /// 邮件阅读标记
        /// </summary>
        public enum ReadFlag
        {
            /// <summary>
            /// 未读
            /// </summary>
            UnRead=0,
            /// <summary>
            /// 已读
            /// </summary>
            Readed = 1
        }

        /// <summary>
        /// 获取邮件阅读标记
        /// </summary>
        /// <param name="itype">枚举类型-邮件阅读标记</param>
        /// <returns></returns>
        public static string GetReadFlag(int itype)
        {
            object value = itype;
            if (Enum.IsDefined(typeof(ReadFlag), value))
            {
                ReadFlag etype = (ReadFlag)itype;
                switch (etype)
                {
                    case ReadFlag.UnRead:
                        return "未读";
                    case ReadFlag.Readed:
                        return "已读";
                }
            }

            return "";
        }

        /// <summary>
        /// 系统数据库类型
        /// </summary>
        public enum DBType
        {
            /// <summary>
            /// MS SQL Server数据库
            /// </summary>
            MsSql = 0 ,
            /// <summary>
            /// Access 数据库
            /// </summary>
            Access = 1 ,
            /// <summary>
            /// Oracle数据库
            /// </summary>
            Oracle = 2
        }

        /// <summary>
        /// 文件类型
        /// </summary>
        public enum FileType
        {
            /// <summary>
            /// Excel 文档
            /// </summary>
            xls ,
            /// <summary>
            /// Word 文档
            /// </summary>
            doc ,
            /// <summary>
            /// Word 文档
            /// </summary>
            docx ,
            /// <summary>
            /// PowerPoint 文档
            /// </summary>
            ppt ,
            /// <summary>
            /// 7Zip 压缩文件
            /// </summary>
            _7zip ,
            /// <summary>
            /// WinRar 压缩文件
            /// </summary>
            rar ,
            /// <summary>
            /// WinZip 压缩文件
            /// </summary>
            zip ,
            /// <summary>
            /// 虚拟光驱文件
            /// </summary>
            iso ,
            /// <summary>
            /// Html文件
            /// </summary>
            htm ,
            /// <summary>
            /// Help 文件
            /// </summary>
            hlp ,
            /// <summary>
            /// Exe 文件
            /// </summary>
            exe ,
            /// <summary>
            /// PDF 文件
            /// </summary>
            pdf ,
            /// <summary>
            /// PSD 文件
            /// </summary>
            psd ,
            /// <summary>
            /// Ai 文件
            /// </summary>
            ai ,
            /// <summary>
            /// Flash 文件
            /// </summary>
            fla ,
            /// <summary>
            /// Flash 文件
            /// </summary>
            swf ,
            /// <summary>
            /// 文本文件
            /// </summary>
            txt ,
            /// <summary>
            /// RMVB 媒体文件
            /// </summary>
            rmvb ,
            /// <summary>
            /// Windows Media Play 媒体文件
            /// </summary>
            asf ,
            /// <summary>
            /// MP3 音乐文件
            /// </summary>
            mp3 ,
            /// <summary>
            /// JPG 图片
            /// </summary>
            jpg ,
            gif ,
            png ,
            bmp ,
            tif ,
            emf ,
            wmf ,
            ico ,
            raw ,
            /// <summary>
            /// CoreDraw
            /// </summary>
            cdr ,
            /// <summary>
            /// BT 种子
            /// </summary>
            bt ,
            /// <summary>
            /// 其它
            /// </summary>
            other
        }

        /// <summary>
        /// 获取文件类型对应的缩略图
        /// </summary>
        /// <param name="type">文件后缀</param>
        /// <returns></returns>
        public static string GetFileTypeThumbnail( string type )
        {
            if ( Enum.IsDefined( typeof( FileType ) , type ) )
            {
                return "thumb_" + Enum.Parse( typeof( FileType ) , type , true ).ToString( ) + ".gif";
            }
            // 针对特殊类型要提出来写，因为枚举不允许数字开头
            //，所以要在数字前加字符，但是加了字符后明显跟以前命名规则不同。
            else if ( type.ToLower( ) == FileType._7zip.ToString( ) )
            {
                return "thumb" + Enum.Parse( typeof( FileType ) , type , true ).ToString( ) + ".gif";
            }
            else
            {
                return "thumb_other.gif";
            }
        }

        /// <summary>
        /// 数据类型（1.整数2.小数3.日期4.字符串5.文本）
        /// </summary>
        public enum DBDataType
        {
            Int = 1 ,
            Decimal ,
            DateTime ,
            Nvarchar ,
            Text
        }

        /// <summary>
        /// 控件类型
        /// </summary>
        /// <param name="type">墓地类型</param>
        /// <returns></returns>
        public static string GetDBDataType( string type )
        {
            if ( Enum.IsDefined( typeof( DBDataType ) , type ) )
            {
                DBDataType ctype = ( DBDataType ) Enum.Parse( typeof( DBDataType ) , type , true );
                switch ( ctype )
                {
                    case DBDataType.Int:
                        return "整数";
                    case DBDataType.Decimal:
                        return "小数";
                    case DBDataType.DateTime:
                        return "日期";
                    case DBDataType.Nvarchar:
                        return "字符串";
                    case DBDataType.Text:
                        return "文本";
                }
            }            

            return "";
        }

        /// <summary>
        /// 审批状态
        /// </summary>
        public enum AditStatus
        {
            /// <summary>
            /// 待审批
            /// </summary>
            WaitForAdit = 1 ,
            /// <summary>
            /// 审批通过
            /// </summary>
            AditPass ,
            /// <summary>
            /// 审批未通过
            /// </summary>
            AditUnpass
        }

        /// <summary>
        /// 获取审批状态
        /// </summary>
        /// <param name="status">审批状态</param>
        /// <returns></returns>
        public static string GetAditStatus( AditStatus status )
        {
            AditStatus sta = ( AditStatus ) status;
            switch ( sta )
            {
                case AditStatus.WaitForAdit:
                    return "待审批";
                case AditStatus.AditPass:
                    return "审批通过";
                case AditStatus.AditUnpass:
                    return "审批未通过";
            }

            return "";
        }

        /// <summary>
        /// 数据字典项
        /// </summary>
        public enum Dictionary
        {
            /// <summary>
            /// 生产商类别分类字段名称
            /// </summary>
            ProducerType ,
            /// <summary>
            /// 品牌类别分类
            /// </summary>
            TrademarkType
        }

        /// <summary>
        /// 控件类型
        /// </summary>
        public enum ControlType
        {
            /// <summary>
            /// 单行文本
            /// </summary>
            TextType ,
            /// <summary>
            /// 多行文本
            /// </summary>
            MultipleTextType ,
            /// <summary>
            /// 选项
            /// </summary>
            ListBoxType ,
            /// <summary>
            /// 数字
            /// </summary>
            NumberType ,
            /// <summary>
            /// 货币
            /// </summary>
            MoneyType ,
            /// <summary>
            /// 日期和时间
            /// </summary>
            DateTimeType ,
            /// <summary>
            /// 查阅项
            /// </summary>
            LookType ,
            /// <summary>
            /// 超链接
            /// </summary>
            LinkType ,
            /// <summary>
            /// 是/否（复选框）
            /// </summary>
            BoolType ,
            /// <summary>
            /// 图片
            /// </summary>
            PictureType ,
            /// <summary>
            /// 颜色代码
            /// </summary>
            ColorType ,
            /// <summary>
            /// 运行平台
            /// </summary>
            OperatingType ,
            /// <summary>
            /// 行政区划
            /// </summary>
            RegionType ,
            /// <summary>
            /// 关键字
            /// </summary>
            KeywordType ,
            /// <summary>
            /// 内容
            /// </summary>
            ContentType ,
            /// <summary>
            /// 选择用户
            /// </summary>
            SelectUser ,
            /// <summary>
            /// 多图片
            /// </summary>
            MultiplePhotoType ,
            /// <summary>
            /// 多级联动
            /// </summary>
            LinkageType ,
            /// <summary>
            /// 作者
            /// </summary>
            AuthorType ,
            /// <summary>
            /// 来源
            /// </summary>
            SourceType ,
        }

        /// <summary>
        /// 字段类型
        /// </summary>
        public enum FieldType
        {
            /// <summary>
            /// 单行文本
            /// </summary>
            TextType ,
            /// <summary>
            /// 多行文本（不支持HTML）
            /// </summary>
            MultipleTextType ,
            /// <summary>
            /// 多行文本（支持HTML）
            /// </summary>
            MultipleHtmlTextType ,
            /// <summary>
            /// 选项
            /// </summary>
            ListBoxType ,
            /// <summary>
            /// 数字
            /// </summary>
            NumberType ,
            /// <summary>
            /// 货币
            /// </summary>
            MoneyType ,
            /// <summary>
            /// 日期和时间
            /// </summary>
            DateTimeType ,
            /// <summary>
            /// 查阅项
            /// </summary>
            LookType ,
            /// <summary>
            /// 超链接
            /// </summary>
            LinkType ,
            /// <summary>
            /// 是/否（复选框）
            /// </summary>
            BoolType ,
            /// <summary>
            /// 图片
            /// </summary>
            PictureType ,
            /// <summary>
            /// 文件
            /// </summary>
            FileType ,
            /// <summary>
            /// 颜色代码
            /// </summary>
            ColorType ,
            /// <summary>
            /// 运行平台
            /// </summary>
            OperatingType ,
            /// <summary>
            /// 行政区划
            /// </summary>
            RegionType ,
            /// <summary>
            /// 关键字
            /// </summary>
            KeywordType ,
            /// <summary>
            /// 内容
            /// </summary>
            ContentType ,
            /// <summary>
            /// 选择用户
            /// </summary>
            SelectUser ,
            /// <summary>
            /// 多图片
            /// </summary>
            MultiplePhotoType ,
            /// <summary>
            /// 多级联动
            /// </summary>
            LinkageType ,
            /// <summary>
            /// 标题
            /// </summary>
            TitleType ,
            /// <summary>
            /// 虚链接
            /// </summary>
            InfoType ,
            /// <summary>
            /// 模板
            /// </summary>
            TemplateType ,
            /// <summary>
            /// 专题
            /// </summary>
            SpecialType ,
            /// <summary>
            /// 节点
            /// </summary>
            NodeType ,
            /// <summary>
            /// 状态
            /// </summary>
            StatusType ,
            /// <summary>
            /// 风格
            /// </summary>
            SkinType ,
            /// <summary>
            /// 作者
            /// </summary>
            AuthorType ,
            /// <summary>
            /// 来源
            /// </summary>
            SourceType ,
            /// <summary>
            /// 下载服务器
            /// </summary>
            DownServerType ,
            /// <summary>
            /// 厂商
            /// </summary>
            Producer ,
            /// <summary>
            /// 品牌
            /// </summary>
            Trademark ,
            /// <summary>
            /// 商品属性
            /// </summary>
            Property ,
            /// <summary>
            /// 商品款式
            /// </summary>
            ProductStyle ,
            /// <summary>
            /// 用户名
            /// </summary>
            UserNameType ,
            /// <summary>
            /// IP地址
            /// </summary>
            IPType
        }

        /// <summary>
        /// 获取SQL字段数据类型
        /// </summary>
        /// <param name="ect">控件类型</param>
        /// <param name="length">长度</param>
        /// <returns></returns>
        public static string GetSqlDataType( string controlType , int length )
        {
            if( length <= 0 )
                length = 255;

            if ( Enum.IsDefined( typeof( ControlType ) , controlType ) )
            {
                ControlType ctype = ( ControlType )Enum.Parse( typeof( ControlType ) , controlType , true );
                switch ( ctype )
                {
                    case ControlType.TextType:
                    case ControlType.ListBoxType:
                    case ControlType.LookType:
                    case ControlType.LinkType:
                    case ControlType.ColorType:
                    case ControlType.OperatingType:
                    case ControlType.RegionType:
                    case ControlType.KeywordType:
                    case ControlType.SelectUser:
                    case ControlType.LinkageType:
                    case ControlType.AuthorType:
                    case ControlType.SourceType:
                        return " nvarchar(" + length + ") ";
                    /// <summary>
                    /// 数字
                    /// </summary>
                    case ControlType.NumberType:
                        return " decimal(18,2) ";
                    /// <summary>
                    /// 货币
                    /// </summary>
                    case ControlType.MoneyType:
                        return " money ";
                    /// <summary>
                    /// 日期和时间
                    /// </summary>
                    case ControlType.DateTimeType:
                        return " datetime ";
                    /// <summary>
                    /// 是/否（复选框）
                    /// </summary>
                    case ControlType.BoolType:
                        return " bit ";
                    /// <summary>
                    /// 内容
                    /// </summary>
                    case ControlType.MultipleTextType:
                    case ControlType.ContentType:
                        return " ntext ";
                    case ControlType.PictureType:
                    case ControlType.MultiplePhotoType:
                        return " varbinary ";
                }
            }

            return " nvarchar(255) ";
        }

        /// <summary>
        /// 换行符
        /// </summary>
        public const string NewLine = "\r\n";
        
        /// <summary>
        /// 模块根目录编号标识
        /// </summary>
        public const string ModuleRoot = "0";

        /// <summary>
        /// 树根目录编号标识
        /// </summary>
        public const string TreeRoot = "0";

        /// <summary>
        /// 用户基础信息全局Session变量，胜于存放用户基础信息，类型：DAtbUserTable
        /// </summary>
        public const string se_UserObject = "se_UserObject";

        /// <summary>
        /// 用户权限信息列表全局Session变量，胜于存放用户基础信息，类型：Hasthtable(ModuleID,Rights)
        /// </summary>
        public const string se_UserRightList = "se_UserRightList";

        #endregion 
    }
}
